home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / plugins / HTMLWindow.jar / horst / ComponentView.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  3.9 KB  |  122 lines

  1. package horst;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Rectangle;
  8. import java.awt.Shape;
  9. import java.util.Hashtable;
  10.  
  11. public class ComponentView extends View {
  12.    protected Component m_comp;
  13.    String m_alt;
  14.  
  15.    public ComponentView(View parent, Element e, HTMLPane container) {
  16.       super(parent, e, container);
  17.    }
  18.  
  19.    protected void drawFocusBox(Graphics g) {
  20.       g.setColor(Color.orange);
  21.  
  22.       for(int i = 0; i <= 3; ++i) {
  23.          g.drawRect(super.m_bounds.x + i, super.m_bounds.y + i, super.m_bounds.width - 2 * i, super.m_bounds.height - 2 * i);
  24.       }
  25.  
  26.    }
  27.  
  28.    protected void flushResources() {
  29.       if (this.m_comp != null) {
  30.          this.m_comp.removeMouseMotionListener(super.m_container);
  31.          this.m_comp = null;
  32.       }
  33.  
  34.    }
  35.  
  36.    protected int getMinimumSpan(int axis) {
  37.       return this.getPreferredSpan(axis);
  38.    }
  39.  
  40.    protected int getPreferredSpan(int axis) {
  41.       if (this.m_comp != null) {
  42.          Dimension size = this.m_comp.getPreferredSize();
  43.          switch (axis) {
  44.             case 0:
  45.                return size.height + super.m_insets.top + super.m_insets.bottom;
  46.             case 1:
  47.                return size.width + super.m_insets.left + super.m_insets.right;
  48.          }
  49.       }
  50.  
  51.       return 0;
  52.    }
  53.  
  54.    protected String getToolTipText() {
  55.       return this.m_alt != null ? this.m_alt : "";
  56.    }
  57.  
  58.    protected void init() {
  59.       Hashtable atts = super.m_elem.getAttributes();
  60.       this.m_alt = (String)super.m_elem.getAttribute("alt");
  61.       this.m_comp = (Component)super.m_elem.getAttribute("component");
  62.       if (this.m_comp != null) {
  63.          this.m_comp.addMouseMotionListener(super.m_container);
  64.          this.m_comp.setVisible(true);
  65.          super.m_container.add(this.m_comp);
  66.       }
  67.  
  68.    }
  69.  
  70.    protected boolean isContainerView() {
  71.       return false;
  72.    }
  73.  
  74.    protected boolean isDisplayableView() {
  75.       return this.m_comp != null;
  76.    }
  77.  
  78.    protected Rectangle layout(int x, int y, int width, LayoutInfo info) {
  79.       super.m_bounds = new Rectangle(x, y, 0, 0);
  80.       if (this.m_comp != null) {
  81.          int compWidth = 0;
  82.          int compHeight = 0;
  83.          int pspan = this.getPreferredSpan(1);
  84.          if (pspan <= width) {
  85.             Dimension sz = this.m_comp.getPreferredSize();
  86.             compWidth = sz.width;
  87.             compHeight = sz.height;
  88.             width = pspan;
  89.          } else {
  90.             Dimension sz = this.m_comp.getPreferredSize();
  91.             compWidth = Math.max(0, width - super.m_insets.left - super.m_insets.right);
  92.             compHeight = sz.height;
  93.          }
  94.  
  95.          Dimension size = this.m_comp.getSize();
  96.          this.m_comp.setBounds(super.m_bounds.x + super.m_insets.left, super.m_bounds.y + super.m_insets.top, compWidth, compHeight);
  97.          super.m_bounds = new Rectangle(x, y, width, compHeight + super.m_insets.top + super.m_insets.bottom);
  98.       }
  99.  
  100.       return super.m_bounds;
  101.    }
  102.  
  103.    protected void move(int x, int y, boolean bMoveFloaters) {
  104.       Rectangle var10000 = super.m_bounds;
  105.       var10000.x += x;
  106.       var10000 = super.m_bounds;
  107.       var10000.y += y;
  108.       if (this.m_comp != null) {
  109.          Dimension size = this.m_comp.getSize();
  110.          this.m_comp.setBounds(super.m_bounds.x + super.m_insets.left, super.m_bounds.y + super.m_insets.top, size.width, size.height);
  111.       }
  112.  
  113.    }
  114.  
  115.    public void paint(Graphics g, Shape alloc) {
  116.       if (this.m_comp != null) {
  117.          this.m_comp.setVisible(super.m_bounds.intersects(alloc.getBounds()));
  118.       }
  119.  
  120.    }
  121. }
  122.